package turing.forum.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import turing.forum.repository.mapper.UserMapper;
import turing.forum.repository.po.User;
import turing.forum.service.IUserService;

@Service
public class UserService implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User register(User user, String password) {
        user.setPassword(password);
        int ret = userMapper.insert(user);
        if (ret != 1) {
            return null;
        }
        return user;
    }

    @Override
    public User login(User user, String password) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>()
                .eq("password", password)
                .eq("username", user.getUsername());
        User loginUser = userMapper.selectOne(wrapper);
        return loginUser;
    }

    @Override
    public String updateInfo(User user) {
        int ret = userMapper.updateById(user);
        return String.valueOf(ret);
    }
}
